package com.lzy.cloud.base.facade;

import com.github.pagehelper.PageInfo;
import com.lzy.cloud.base.dto.ShopBankDto;
import com.lzy.cloud.base.service.ShopBankService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.output.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商家开户银行
 *
 * @author lc
 * @version 2018/8/16
 */
@Component
public class ShopBankFacade {

    @Autowired
    private ShopBankService shopBankService;

    /**
     * 新增
     * @param dto
     * @return
     */
    public Long create(ShopBankDto dto) {
        //先查询银行卡号是否被绑定
        ShopBankDto exist = shopBankService.findByAccount(dto.getAccount());
        if (exist != null){
            return 0L;
        }
        return shopBankService.create(dto);
    }

    /**
     * 根据卡号查询
     * @param account
     * @return
     */
    public ShopBankDto findByAccount(String account) {
        return shopBankService.findByAccount(account);
    }

    /**
     * 分页查询
     * @param pager
     * @param map
     * @return
     */
    public PageInfo<ShopBankDto> selectList(Pager pager, ShopBankDto map) {
        return shopBankService.selectList(pager,map);
    }

    /**
     * 编辑
     * @param map
     * @return
     */
    public Boolean update(ShopBankDto map) {
        Ensure.that(map.getId()).isNotNull("00000002");
        return shopBankService.update(map);
    }
}
